﻿using System.Collections.Generic;

namespace Sidvall.AuthorizationManager.Data
{
	public class CriteriaItemDictionary : Dictionary<string, CriteriaItem>
	{
		#region Public Members

		#region GetCriteriaItem

		public CriteriaItem GetCriteriaItem()
		{
			CriteriaItem item;

			if (TryGetValue(string.Empty, out item))
				return item;
			return null;
		}
		public CriteriaItem GetCriteriaItem(string criteriaId)
		{
			CriteriaItem item;

			if (!string.IsNullOrWhiteSpace(criteriaId))
			{
				if (TryGetValue(criteriaId, out item))
					return item;
			}
			return GetCriteriaItem();
		}

		#endregion
		#region Load

		public void Load(IEnumerable<string> items)
		{
			CriteriaItem criteriaItem;
			string id;

			if (items == null)
				return;
			foreach (var item in items)
			{
				criteriaItem = new CriteriaItem();
				if (item == null)
					id = string.Empty;
				else
					id = item.Trim();
				if (!ContainsKey(id))
					Add(id, criteriaItem);
			}
		}

		#endregion

		#endregion
		#region Constructors

		public CriteriaItemDictionary()
			: base()
		{

		}
		public CriteriaItemDictionary(IEqualityComparer<string> comparer)
			: base(comparer)
		{
		}

		#endregion
	}
}
